﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace MS.InformationManagement.Support
{
    public static class StringExtensionsHelper
    {

        public static IList<string> ToIListCollection(this string Input, char separator)
        {
            return Input.Split(separator);
        }

        public static string GetUserWithOutDomain(this string Input)
        {
            if (Input.Split('\\').Length > 1)
                return Input.Split('\\')[1];
            else
                return Input;
        }

        public static string GetEntityFieldUrl(this string Input)
        {
            if (Input.Split(',').Length > 1)
                return Input.Split(',')[0];
            else
                return Input;
        }

        public static string GetUserListNameFromUrl(this string Input)
        {
            string urlWithOutWebUrl = Input.Replace(SPContext.Current.Web.Url+"/", string.Empty);
            return urlWithOutWebUrl.Split('/')[0] == "Lists" ? urlWithOutWebUrl.Split('/')[1] : urlWithOutWebUrl.Split('/')[0];
        }
    }
}
